public class Sudoku {
	private int[][] su;
	private int x;
	private int y;

	public Sudoku() {
		su = new int[9][9];

	}

	private boolean solve(int a,int b,int[][] su){
        if(a == 9){
            a = 0;
            if( ++b == 9){
                return true;
            }
        }
        if(su[a][b]!=0 ){
            return solve(a+1,b,su);
        }

        for(int i = 1; i < 10; i++){
            if( ok(a,b,i)){
                su[a][b] = i;
                x++;
                if(solve(a+1, b, su)){
                    return true;
                }
            }
        }
        su[a][b] = 0;
        return false;
    }

	private boolean cSquare(int x, int y, int n) {
		int a, b;

		a = (x/3)*3;
		b = (y/3)*3;
		for (int i = b; i < b + 3; i++) {
			for (int j = a; j < a + 3; j++) {
				if(j == x && i == y){
					
				}
				else if (su[j][i] == n) {
					return false;
				}
			}
		}
		return true;

	}

	private boolean cHorisontal(int y, int n) {
		for (int i = 0; i < su.length; i++) {
			if(i == x){
				
			}
			else if (su[i][y] == n) {
				return false;
			}
		}
		return true;
	}

	private boolean cVertical(int x, int n) {
		for (int i = 0; i < su.length; i++) {
			if(i == y){
				
			}
			else if (su[x][i] == n) {
				return false;
			}
		}
		return true;
	}

	private boolean ok(int a, int b, int n){
		if(cHorisontal(b, n) && cVertical(a, n) && cSquare(a, b, n)){
			return true;
		} 
		return false;
	}

}